package com.gome.ss.core.schedule;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.quartz.Trigger;
import org.quartz.TriggerBuilder;


public class TriggerStartAt extends TriggerConfig implements TriggerStart{
	private String name = "start-at";
	private String group = "once";
	private Date at;
	
	public TriggerStartAt(String time) throws ParseException {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		this.at = sdf.parse(time);
		this.setTriggerName(name);
		this.setTrggerGroup(group);
		this.triggerType = TriggerConfig.NORMAL_TYPE;
	}
	
	public void setName(String name) {
		this.name = name;
		this.setTriggerName(name);
	}
	
	public void setGroup(String group) {
		this.group = group;
		this.setTrggerGroup(group);
	}
	
	public Trigger getTrigger() {
		Trigger trigger = TriggerBuilder.newTrigger().withIdentity(this.getTriggerName(), this.getTrggerGroup()).startAt(at).build();
		return trigger;
	}

	@Override
	public String time() {
		return at.toString();
	}
}
